<template>
  <div class="app-container">
    <!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="被检查人员名称或姓名" prop="scReqName">
            <el-input
              v-model="queryParams.scReqName"
              placeholder="请输入被检查人员名称或姓名"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="时间" prop="scInspectTime">
            <el-input
              v-model="queryParams.scInspectTime"
              placeholder="请输入时间"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="时间段" prop="scTemporal">
            <el-input
              v-model="queryParams.scTemporal"
              placeholder="请输入时间段"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="地点" prop="scAd">
            <el-input
              v-model="queryParams.scAd"
              placeholder="请输入地点"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="现场负责人" prop="scUser">
            <el-input
              v-model="queryParams.scUser"
              placeholder="请输入现场负责人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="现场负责人电话" prop="scTel">
            <el-input
              v-model="queryParams.scTel"
              placeholder="请输入现场负责人电话"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="邮编" prop="scPCode">
            <el-input
              v-model="queryParams.scPCode"
              placeholder="请输入邮编"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="现场负责人工作单位" prop="scUnit">
            <el-input
              v-model="queryParams.scUnit"
              placeholder="请输入现场负责人工作单位"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="现场负责人职务" prop="scDuty">
            <el-input
              v-model="queryParams.scDuty"
              placeholder="请输入现场负责人职务"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="记录人" prop="scRecorder">
            <el-input
              v-model="queryParams.scRecorder"
              placeholder="请输入记录人"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="记录人单位" prop="scRecUnit">
            <el-input
              v-model="queryParams.scRecUnit"
              placeholder="请输入记录人单位"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="现场情况" prop="scCondition">
            <el-input
              v-model="queryParams.scCondition"
              placeholder="请输入现场情况"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="确认意见" prop="scConform">
            <el-input
              v-model="queryParams.scConform"
              placeholder="请输入确认意见"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="被检查人或现场负责人签字" prop="scReq">
            <el-input
              v-model="queryParams.scReq"
              placeholder="请输入被检查人或现场负责人签字"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="被检查人签字时间" prop="scReqTime">
            <el-date-picker clearable size="small"
              v-model="queryParams.scReqTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择被检查人签字时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="检查人签字" prop="scCu">
            <el-input
              v-model="queryParams.scCu"
              placeholder="请输入检查人签字"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="检查人签字时间" prop="scCuTime">
            <el-date-picker clearable size="small"
              v-model="queryParams.scCuTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择检查人签字时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="记录人签字" prop="scRec">
            <el-input
              v-model="queryParams.scRec"
              placeholder="请输入记录人签字"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="记录人签字时间" prop="scRecTime">
            <el-date-picker clearable size="small"
              v-model="queryParams.scRecTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择记录人签字时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="参加人签字" prop="scVenor">
            <el-input
              v-model="queryParams.scVenor"
              placeholder="请输入参加人签字"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="参加人签字时间" prop="scVenorTime">
            <el-date-picker clearable size="small"
              v-model="queryParams.scVenorTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择参加人签字时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="企业ID" prop="epId">
            <el-input
              v-model="queryParams.epId"
              placeholder="请输入企业ID"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['check:spot:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['check:spot:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['check:spot:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['check:spot:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="spotList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="执法ID" align="center" prop="scId" />-->
      <el-table-column label="被检查单位" align="center" prop="scReqName"/>
      <el-table-column label="时间" align="center" prop="scInspectTime"/>
      <!--      <el-table-column label="时间段" align="center" prop="scTemporal" />-->
      <el-table-column label="地点" align="center" prop="scAd"/>
      <el-table-column label="现场负责人" align="center" prop="scUser"/>
      <el-table-column label="现场负责人电话" align="center" prop="scTel"/>
      <!--      <el-table-column label="邮编" align="center" prop="scPCode" />-->
      <!--      <el-table-column label="现场负责人工作单位" align="center" prop="scUnit" />-->
      <el-table-column label="现场负责人职务" align="center" prop="scDuty"/>
      <el-table-column label="记录人" align="center" prop="scRecorder"/>
      <el-table-column label="记录人单位" align="center" prop="scRecUnit"/>
      <el-table-column label="现场情况" align="center" prop="scCondition"/>
      <!--      <el-table-column label="确认意见" align="center" prop="scConform" />-->
      <!--      <el-table-column label="被检查人或现场负责人签字" align="center" prop="scReq" />-->
      <!--      <el-table-column label="被检查人签字时间" align="center" prop="scReqTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.scReqTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="检查人签字" align="center" prop="scCu" />-->
      <!--      <el-table-column label="检查人签字时间" align="center" prop="scCuTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.scCuTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="记录人签字" align="center" prop="scRec" />-->
      <!--      <el-table-column label="记录人签字时间" align="center" prop="scRecTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.scRecTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="参加人签字" align="center" prop="scVenor" />-->
      <!--      <el-table-column label="参加人签字时间" align="center" prop="scVenorTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.scVenorTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="企业ID" align="center" prop="epId" />-->
      <!--      <el-table-column label="备注" align="center" prop="remark" />-->
      <!--      <el-table-column label="冗余字段" align="center" prop="other" />-->
      <!--      <el-table-column label="冗余字段" align="center" prop="otherOne" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['check:spot:edit']"
          >修改
          </el-button>
          <el-button
            size="small"
            @click="handleDelete(scope.row)"
            v-hasPermi="['check:spot:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改执法信息录入对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body class="app-container-atmosphere" width="60%">
      <el-form ref="form" :model="form" :rules="rules" class="clearfix" label-width="140px">
        <div class="content-left" style="margin-left: 4%">
          <div class="title2"><span> </span>基本信息</div>
          <el-form-item label="被检查单位" prop="scReqName">
            <el-input v-model="form.scReqName" placeholder="请输入被检查单位"/>
          </el-form-item>
          <el-form-item label="时间" prop="scInspectTime">
            <el-input v-model="form.scInspectTime" placeholder="请输入时间"/>
          </el-form-item>
          <!--        <el-form-item label="时间段" prop="scTemporal">-->
          <!--          <el-input v-model="form.scTemporal" placeholder="请输入时间段" />-->
          <!--        </el-form-item>-->
          <el-form-item label="地点" prop="scAd">
            <el-input v-model="form.scAd" placeholder="请输入地点"/>
          </el-form-item>
          <el-form-item label="现场负责人" prop="scUser">
            <el-input v-model="form.scUser" placeholder="请输入现场负责人"/>
          </el-form-item>
          <el-form-item label="现场负责人电话" prop="scTel">
            <el-input v-model="form.scTel" placeholder="请输入现场负责人电话"/>
          </el-form-item>
          <!--        <el-form-item label="邮编" prop="scPCode">-->
          <!--          <el-input v-model="form.scPCode" placeholder="请输入邮编" />-->
          <!--        </el-form-item>-->
          <el-form-item label="现场负责人工作单位" prop="scUnit">
            <el-input v-model="form.scUnit" placeholder="请输入现场负责人工作单位"/>
          </el-form-item>
          <el-form-item label="现场负责人职务" prop="scDuty">
            <el-input v-model="form.scDuty" placeholder="请输入现场负责人职务"/>
          </el-form-item>
        </div>
        <div class="content-left" style="margin-left: 15%">
          <div class="title2"><span> </span>现场信息</div>
          <el-form-item label="记录人" prop="scRecorder">
            <el-input v-model="form.scRecorder" placeholder="请输入记录人"/>
          </el-form-item>
          <el-form-item label="记录人单位" prop="scRecUnit">
            <el-input v-model="form.scRecUnit" placeholder="请输入记录人单位"/>
          </el-form-item>
          <el-form-item label="现场情况" prop="scCondition">
            <el-input v-model="form.scCondition" placeholder="请输入现场情况"/>
          </el-form-item>
          <el-form-item label="确认意见" prop="scConform">
            <el-input v-model="form.scConform" placeholder="请输入确认意见"/>
          </el-form-item>
          <el-form-item label="被检查人或现场负责人签字" prop="scReq">
            <el-input v-model="form.scReq" placeholder="请输入被检查人或现场负责人签字"/>
          </el-form-item>
          <!--        <el-form-item label="被检查人签字时间" prop="scReqTime">-->
          <!--          <el-date-picker clearable size="small"-->
          <!--            v-model="form.scReqTime"-->
          <!--            type="date"-->
          <!--            value-format="yyyy-MM-dd"-->
          <!--            placeholder="选择被检查人签字时间">-->
          <!--          </el-date-picker>-->
          <!--        </el-form-item>-->
          <el-form-item label="检查人签字" prop="scCu">
            <el-input v-model="form.scCu" placeholder="请输入检查人签字"/>
          </el-form-item>
          <!--        <el-form-item label="检查人签字时间" prop="scCuTime">-->
          <!--          <el-date-picker clearable size="small"-->
          <!--            v-model="form.scCuTime"-->
          <!--            type="date"-->
          <!--            value-format="yyyy-MM-dd"-->
          <!--            placeholder="选择检查人签字时间">-->
          <!--          </el-date-picker>-->
          <!--        </el-form-item>-->
          <el-form-item label="记录人签字" prop="scRec">
            <el-input v-model="form.scRec" placeholder="请输入记录人签字"/>
          </el-form-item>
          <!--        <el-form-item label="记录人签字时间" prop="scRecTime">-->
          <!--          <el-date-picker clearable size="small"-->
          <!--            v-model="form.scRecTime"-->
          <!--            type="date"-->
          <!--            value-format="yyyy-MM-dd"-->
          <!--            placeholder="选择记录人签字时间">-->
          <!--          </el-date-picker>-->
          <!--        </el-form-item>-->
          <el-form-item label="参加人签字" prop="scVenor">
            <el-input v-model="form.scVenor" placeholder="请输入参加人签字"/>
          </el-form-item>
        </div>
        <!--        <el-form-item label="参加人签字时间" prop="scVenorTime">-->
        <!--          <el-date-picker clearable size="small"-->
        <!--            v-model="form.scVenorTime"-->
        <!--            type="date"-->
        <!--            value-format="yyyy-MM-dd"-->
        <!--            placeholder="选择参加人签字时间">-->
        <!--          </el-date-picker>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="企业ID" prop="epId">
                  <el-input v-model="form.epId" placeholder="请输入企业ID" />
                </el-form-item>
                <el-form-item label="删除标志" prop="delFlag">
                  <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item label="冗余字段" prop="other">
                  <el-input v-model="form.other" type="textarea" placeholder="请输入内容" />
                </el-form-item>
                <el-form-item label="冗余字段" prop="otherOne">
                  <el-input v-model="form.otherOne" type="textarea" placeholder="请输入内容" />
                </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center;">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addSpot, delSpot, exportSpot, getSpot, listSpot, updateSpot} from "@/api/check/spot";
import {isIntegerNotMust,validatePhoneTwo,validateIdNo,validateEMail} from "@/api/validate/validate";

export default {
  name: "Spot",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 执法信息录入表格数据
      spotList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        scReqName: null,
        scInspectTime: null,
        scTemporal: null,
        scAd: null,
        scUser: null,
        scTel: null,
        scPCode: null,
        scUnit: null,
        scDuty: null,
        scRecorder: null,
        scRecUnit: null,
        scCondition: null,
        scConform: null,
        scReq: null,
        scReqTime: null,
        scCu: null,
        scCuTime: null,
        scRec: null,
        scRecTime: null,
        scVenor: null,
        scVenorTime: null,
        epId: null,
        other: null,
        otherOne: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        scReqName: [
          {required: true, message: "被检查单位不能为空", trigger: "blur"}
        ],
        scRecorder: [
          {required: true, message: "记录人不能为空", trigger: "blur"}
        ],
        scInspectTime: [
          {required: true, message: "时间不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询执法信息录入列表 */
    getList() {
      this.loading = true;
      listSpot(this.queryParams).then(response => {
        this.spotList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        scId: null,
        scReqName: null,
        scInspectTime: null,
        scTemporal: null,
        scAd: null,
        scUser: null,
        scTel: null,
        scPCode: null,
        scUnit: null,
        scDuty: null,
        scRecorder: null,
        scRecUnit: null,
        scCondition: null,
        scConform: null,
        scReq: null,
        scReqTime: null,
        scCu: null,
        scCuTime: null,
        scRec: null,
        scRecTime: null,
        scVenor: null,
        scVenorTime: null,
        epId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        other: null,
        otherOne: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.scId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加执法信息录入";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const scId = row.scId || this.ids
      getSpot(scId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改执法信息录入";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.scId != null) {
            updateSpot(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSpot(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const scIds = row.scId || this.ids;
      this.$confirm('是否确认删除执法信息录入编号为"' + scIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delSpot(scIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有执法信息录入数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportSpot(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }
};
</script>
